//
// Created by yonghu0 on 25-10-31.
//

#ifndef JUDGER_H
#define JUDGER_H

#include <jsoncpp/json/json.h>

enum Status
{
    PJ, // PJ "Pending & Judging"
    CE, // CE "Compile Error"
    AC, // AC "Accepted"
    WA, // WA "Wrong Answer"
    RE, // RE "Runtime Error"
    TLE, // TLE "Time Limit Exceeded"
    MLE, // MLE "Memory Limit Exceeded"
    SE // SE "System Error"
};

class Judger
{
public:
    Judger();

    Json::Value Run(Json::Value &runjson);

private:
    std::string m_submitid;
    std::string m_problemid;
    int m_judgenum;
    std::string m_code;
    std::string m_language;
    int m_timelimit;
    int m_maxtimelimit;
    long m_memorylimit;
    long m_maxmemorylimit;

    std::string m_runpath;
    std::string m_datapath;
    bool m_isspj;
    std::string m_command;

    Json::Value m_resjson;
    Status m_result;
    std::string m_reason;
    std::string m_length;
    int m_runtime;
    long m_runmemory;


    bool Init(Json::Value &initjson);

    bool CompileC();
    bool CompileCpp();
    bool CompileGo();
    bool CompilePython2();
    bool CompilePython3();
    bool CompileJava();
    bool CompileJavaScript();

    bool RunProgramC_Cpp();
    bool RunProgramGo();
    bool RunProgramPython2();
    bool RunProgramPython3();
    bool RunProgramJava();
    bool RunProgramJavaScript();

    Json::Value Done();
    bool GetCompilationFailed();
    bool RunProgram(struct config &conf);
    bool JudgmentResult(struct result &result, std::string &index);
    bool CompileSPJ();
};


#endif //JUDGER_H
